require 'rexml/document'
require 'comment_data'
require 'post_data'


def parse_comments_nodelist(file_name)
  main_document = REXML::Document.new File.new(file_name)
  author, content,  email, website, ip_address, post_date_sql, state = [],[],[],[],[],[],[]

  comment_nodelist  = main_document.elements.to_a("//comment")
  comment_nodelist.each {|e|
    content << e.get_text("body").value
    author << e.get_text("author").value
    email << (e.get_text("email").nil? ? '' : e.get_text("email").value)
    website << (e.get_text("website").nil? ? '' : e.get_text("website").value)
    ip_address << e.get_text("ipAddress").value
    post_date_sql << e.get_text("date").value
    state << e.get_text("state").value
  }
    comment_data = CommentData.new(content,author,email,website,ip_address,post_date_sql,state)
    return comment_data
end

def parse_xml(fileName)
  main_document = REXML::Document.new File.new(fileName)
  content = main_document.root.get_text('body').value
  post_date = main_document.root.get_text('date').value
  title = main_document.root.get_text('title').value
  excerpt = main_document.root.get_text('excerpt').value
  comments_count  = main_document.elements.to_a("//comment").size
  post_data = PostData.new(content,post_date,title,excerpt,comments_count)
  return post_data
end